<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 100%;
        }
        button{
            width: 100px;   
            height: 30px;
            margin: 20px;
            cursor: pointer;
        }
        .mask{
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, .5);
            position: fixed;
            top: 0;
            left: 0;
            display: none;
        }
        .content{      
            width: 400px;
            height: 200px;
            background-color: #fff;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
        }
        .content span{
            width: 20px;
            height: 20px;
            background-color: #e5e5e5;
            position: absolute;
            top: 0;
            right: 0;
            line-height: 20px;
            text-align: center;
            cursor: pointer;
        }
        .content p{
            width: 100%;
            height: 100%;
            line-height: 200px;
            text-align: center;
        }
        .bg1{
            background-color: orange !important;
        }
        .bg2{
            background-color: greenyellow !important;
        }
        .bg3{
            background-color: skyblue !important;
        }
    </style>
</head>
<body>
    <button>弹窗1</button>
    <button>弹窗2</button>
    <button>弹窗3</button>
    <div class="mask">
        <div class="content">
            <span>&times;</span>
            <p>这是一个弹窗</p>
        </div>
    </div>
    <script>
        let aBtn=document.querySelectorAll('button');

        class layer{
            init(bg,con){
                this.mask=document.querySelector('.mask');
                this.content=document.querySelector('.content');
                this.span=document.querySelector('.content span');
                this.p=document.querySelector('.content p');
                this.show();
                this.content.classList.add(bg)
                this.p.innerHTML=con
                this.close(bg)
            }
            show(){
                this.mask.style.display='block';
            }
            close(bg){
                this.span.onclick=()=>{
                    this.content.classList.remove(bg)
                    this.mask.style.display='none';
                }
            }

            static getinstance(bg,con){
                if(!this.instance){
                    this.instance=new layer();
                }
                this.instance.init(bg,con)
                return this.instance;
            }
        }
        aBtn[0].onclick = function(){
            layer.getinstance('bg1', '高伟上课好精神，从来不睡觉！')
        }
        aBtn[1].onclick = function(){
            layer.getinstance('bg2', '许东明已经听懂了！！！')
        }
        aBtn[2].onclick = function(){
            layer.getinstance('bg3', '好好上课！其他的事情和你没有关系。。。')
        }
    </script>
</body>
</html>